package com.yxc.eslibrary.http;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by robin on 15-9-7.
 */
public class HttpParams implements IHttpParams {

    Map<String, String> params = new HashMap<String, String>();

    String charset = "UTF-8";

    @Override
    public String formatParams() {
        StringBuffer result = new StringBuffer();
        for (String key: params.keySet()){
            result.append(key).append("=").append(params.get(key)).append("&");
        }
        if (result.length()>0){
            result.deleteCharAt(result.length()-1);
        }
        return result.toString();
    }

    @Override
    public void addParams(String key, String value) {
        params.put(key, value);
    }

    @Override
    public void addParams(Map<String, String> params) {
//        this.params.putAll(params);
        for (String key: params.keySet()){
            if (!this.params.containsKey(key)){
                this.params.put(key, params.get(key));
            }
        }
    }

    @Override
    public void removeParams(String key) {
        params.remove(key);
    }
}
